<load href="__PUBLIC__/datepicker/css/datetimepicker.css" />
<load href="__PUBLIC__/datepicker/js/datetimepicker.js" />
<div id="data_page" class="in_page">
    <div class="panel panel-default">
        <div class="panel-body" style="position: relative">
            <form class="form-inline" onsubmit="return checkSearch()">
                <div class="form-group">
                    <label >关键字</label>
                    <input  id="keyword" placeholder="产品名称或产品编号" value="{$search.keyword}" type="text" name="keyword" class="form-control"  />
                </div>
                <div class="form-group">
                    <label for="exampleInputName2">用户名</label>
                    <input id="username" value="{$search.username}" type="text" name="username" class="form-control"  placeholder="输入用户名" />
                    <input value="1" type="hidden" name="p" class="form-control" />
                </div>
                <div class="form-group">
                    <label >是否有效</label>
                    <select style="width: 100px;" name="is_valid" id="is_valid" class="form-control">
                        <if condition="$search.is_valid eq '0'">
                            <option value=""  >全部</option>
                            <option value="0" selected  >无效</option>
                            <option value="1">有效</option>
                        </if>
                        <if condition="$search.is_valid eq '1'">
                            <option value=""  >全部</option>
                            <option value="0"  >无效</option>
                            <option value="1" selected  >有效</option>
                        </if>
                        <if condition="$search.is_valid eq ''">
                            <option selected value=""  >全部</option>
                            <option value="0"  >无效</option>
                            <option value="1"   >有效</option>
                        </if>
                    </select>
                </div>
                <div class="form-group">
                    <label >产品类型</label>
                    <select style="width: 100px;" name="type" id="type" class="form-control">
                        <if condition="$search.type eq '0'">
                            <option value=""  >全部</option>
                            <option value="0" selected  >系统产品</option>
                            <option value="1">用户产品</option>
                        </if>
                        <if condition="$search.type eq '1'">
                            <option value=""  >全部</option>
                            <option value="0"  >系统产品</option>
                            <option value="1" selected  >用户产品</option>
                        </if>
                        <if condition="$search.type eq ''">
                            <option selected value=""  >全部</option>
                            <option value="0"  >系统产品</option>
                            <option value="1"   >用户产品</option>
                        </if>
                    </select>
                </div>
                <div class="form-group">
                    <label >是否上架</label>
                    <select style="width: 100px;" name="is_shelves" id="is_shelves" class="form-control">
                        <if condition="$search.is_shelves eq '0'">
                            <option value=""  >全部</option>
                            <option value="0" selected  >下架</option>
                            <option value="1">上架</option>
                        </if>
                        <if condition="$search.is_shelves eq '1'">
                            <option value=""  >全部</option>
                            <option value="0"  >下架</option>
                            <option value="1" selected  >上架</option>
                        </if>
                        <if condition="$search.is_shelves eq ''">
                            <option selected value=""  >全部</option>
                            <option value="0"  >下架</option>
                            <option value="1"   >上架</option>
                        </if>
                    </select>
                </div>
                <button type="submit" class="btn btn-sm btn-default">搜索</button>
                <div class="btn-group">
                    <button type="button" onclick="resetData()" class="btn btn-sm btn-primary">重置</button>
                </div>
            </form>
            <a style="position: absolute;right:5px;top:5px;" class="btn btn-info btn-sm" href="javascript:void(0)" onclick="showIframe('{:U('/balance/addGoods')}','添加产品','80%','96%')">添加产品</a>
        </div>
    </div>
    <table class="table table-bordered">
        <thead>
        <tr>
            <th>#ID</th>
            <th>产品名称</th>
            <th>价格</th>
            <th>余额</th>
            <th>已购买</th>
            <th>产品类型</th>
            <th style="width: 100px; ">状态</th>
            <th>用户信息</th>
            <th>添加时间</th>
            <th>操作</th>
        </tr>
        </thead>
        <volist name="list" id="item">
            <tr>
                <th scope="row">{$item.id}</th>
                <td>编号：{$item.goods_sn} <br />名称：{$item.name}</td>
                <td>￥{$item.price}</td>
                <td>
                    <if condition="$item.type eq 0">
                    <span style="color: green">
                    不限制
                    </span>
                    </if>
                    <if condition="$item.type eq 1">
                    <span style="color: green">
                    {$item.balance}
                    </span>
                    </if>
                    </td>
                <td>{$item.buy_number}</td>
                <td style="text-align: center">
                    <if condition="$item.type eq 0">
                    <span style="color: green">
                    系统产品
                    </span>
                    </if>
                    <if condition="$item.type eq 1">
                    <span style="color: red">
                    用户产品
                    </span>
                    </if>
                </td>
                <td style="text-align: center">
                    <if condition="$item.is_valid eq 1">
                    <span style="color: green">
                    有效
                    </span>
                    </if>
                    <if condition="$item.is_valid eq 0">
                    <span style="color: red">
                    无效
                    </span>
                    </if>
                    <if condition="$item.is_shelves eq 1">
                    <span style="color: green">
                    已上架
                    </span>
                    </if>
                    <if condition="$item.is_shelves eq 0">
                    <span style="color: red">
                    已下架
                    </span>
                    </if>
                </td>
                <td>
                    <if condition="$item.type eq 0">
                        <span style="color: green">系统产品</span>
                    </if>
                    <if condition="$item.type eq 1">
                        <span style="color: red">{$item.username}</span>
                    </if>
                </td>
                <td  style="text-align: center;width: 140px;">{$item.createdtime|date="Y-m-d H:i",###}</td>
                <td style="width: 60px">
                    <button type="button" onclick="handleItem('{:U('/balance/updateGoods')}',{$item.id})" class="btn btn-primary btn-xs">修改</button>
                </td>
            </tr>
        </volist>
    </table>
    {$page}
</div>

<script>
    $(function(){
        $('#begin_time').datetimepicker({
            lang: 'ch',
            format: 'Y-m-d H:i',
            timepicker: true,
            step:10
        });
        $('#end_time').datetimepicker({
            lang: 'ch',
            format: 'Y-m-d H:i',
            timepicker: true,
            step:10
        });
    })
    function checkSearch(){
        _sdate = $("#begin_time").val();
        _etime = $("#end_time").val();
        if (_sdate != '' && _etime == '') {
            alert('请输入时间条件的结束时间');
            return false;
        }
        if (_sdate == '' && _etime != '') {
            alert('请输入时间条件的开始时间');
            return false;
        }
        if (Date.parse(_sdate) - Date.parse(_etime) > 0) {
            alert('时间条件的开始时间不得大于结束时间');
            return false;
        }
        return true;
    }

    function resetData(){
        $("#username").val("");
        $("#to_username").val("");
        $("#begin_time").val("");
        $("#end_time").val("");
    }
    function handleItem(_action,id,_title){
         showIframe(_action+"?id="+id,"修改产品",'80%','96%');
    }
</script>